package com.grsu.phonestation.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.grsu.phonestation.dao.UserDAO;
import com.grsu.phonestation.domain.User;
import com.grsu.phonestation.service.UserService;

@Service
@Transactional
public class UserServiceImpl<U extends User> implements UserService<U> {

	@Autowired
	@Qualifier("userDAOImpl")
	private UserDAO<U> userDAO;


	public UserDAO<U> getDao(){
		return userDAO;
	}
	
	@Override
	public void addUser(U user) {
		getDao().save(user);
	}

	@Override
	public void editUser(U user) {
		getDao().update(user);

	}

	@Override
	public void removeUser(int userId) {
		getDao().remove(userId);

	}

	@Override
	public U getUserById(int userId) {
		return getDao().findById(userId);
	}

	@Override
	public List<U> listUsers() {
		List<U> users = getDao().findAll();
		return users;
	}

	@Override
	public U loadUserByCredentials(String login, String password) {
		return getDao().findByCredentials(login, password);
	}

	@Override
	public U getUserByLogin(String login) {
		return getDao().getUserByLogin(login);
	}

	@Override
	public U getUserByEmail(String email) {
		return getDao().getUserByEmail(email);
	}
}
